# 1、导包
import requests


class RequestDemo():
    # 2、准备url
    def __init__(self):
        # 注册url
        self.register_url = "http://127.0.0.1:5000/registered"
        # 登录url
        self.login_url = "http://127.0.0.1:5000/login"
        # 获取信息
        self.user_url = "http://127.0.0.1:5000/getuser/zhangsan"
        # 删除
        self.exit_url = "http://127.0.0.1:5000/exit/zhangsan"

    def register(self):
        # 3、准备data数据
        data  = {
            "username":"zhangsan",
            "password1":"123456",
            "password2":"123456"
        }
        # 发送请求
        response = requests.post(url=self.register_url, json=data)
        # 4、获取相应信息
        print(response.json())

    def login(self):
        data = {
            "username":"zhangsan",
            "password":"123456"
        }
        response = requests.post(url=self.login_url, json=data)
        print(response.json())

    def getuser(self):
        header = {
            "Authorization":"0.6239793265515887"
        }
        response = requests.get(url=self.user_url,headers=header)
        print(response.json())

    def exit_user(self):
        header = {
            "Authorization":"0.6239793265515887"
        }
        response = requests.delete(url=self.exit_url,headers=header)
        print(response.json())


r = RequestDemo()
# r.register()
r.login()
# r.getuser()
# r.exit_user()